package com.yc.forum.filter;

import com.yc.forum.util.WordUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.List;

class MyFilter extends HttpServletRequestWrapper {
    //这是采用包装模式
    public MyFilter(HttpServletRequest request) {
        super(request);
    }

    @Override //重写这个方法
    public String getParameter(String name) {
        String words = super.getParameter(name);
//        System.out.println("begin:"+words);//过滤前的文字
        List<String> list = WordUtils.getword();
        for (String ll : list) {
            words = words.replace(ll, "*");//敏感词汇采用**代替
        }
        System.out.println("end:"+words);//过滤后的文字
        return words;
    }
}
